<template>
	<view class="empty" v-if="error">
		<u-empty mode="page"></u-empty>
	</view>
	<view class="content" v-else>
		<u-skeleton rows="20" title loading v-if="skeleton"></u-skeleton>
		<view class="" v-else>
			<view class="banner">
				<u-swiper :list="detail_data.logs" :current="currentNum" @change="changeBanner" @click="click"
					indicator="true">
					<view slot="indicator" class="indicator-num">
						<text class="indicator-num__text">{{ currentNum + 1 }}/{{ detail_data.logs.length }}</text>
					</view>
				</u-swiper>
			</view>
			<view class="head">
				<view class="top">
					<view class="top-left">
						{{detail_data.title}}
					</view>
				</view>
				<view class="center">
					<view class="li">
						<view class="li-top">
							{{detail_data.money}}<text v-if="type_index == 1">万</text><text v-else>元/月</text>
						</view>
						<view class="li-bottom">
							<text v-if="type_index == 1">售价</text>
							<text v-else>租金</text>
						</view>
					</view>
					<view class="li">
						<view class="li-top">
							{{detail_data.room}}室{{detail_data.office}}厅{{detail_data.guard}}卫
						</view>
						<view class="li-bottom">
							房型
						</view>
					</view>
					<view class="li">
						<view class="li-top">
							{{detail_data.area}}m²
						</view>
						<view class="li-bottom">
							建筑面积
						</view>
					</view>
				</view>
			</view>
			<view class="header">
				<view class="item" @click="btn_phone(detail_data.mobile)">
					<view class="left">
						<image src="/static/fabu/chuzu.png" mode=""></image>
					</view>
					<view class="center">
						<view class="title">
							南因网络
						</view>
						<view class="wx">
							微信：{{detail_data.wx}}
						</view>
					</view>
					<view class="mobile">
						<u-icon name="phone" size="30" color="#3084bc"></u-icon>
					</view>
				</view>
			</view>

			<view class="container">
				<view class="item">
					<view class="title">
						房源信息
					</view>
					<view class="line"></view>
					<view class="con">
						<view class="li">
							<text class="left">年代:</text>{{detail_data.establish_year}}
						</view>
						<view class="li">
							<text class="left">朝向:</text>{{detail_data.direction}}
						</view>
						<view class="li">
							<text class="left">楼层:</text><text
								v-if="detail_data.floor_line == 0">{{detail_data.floor}}</text><text
								v-else>{{detail_data.floor_line}}</text>/共{{detail_data.count_floor}}层
						</view>
						<view class="li">
							<text class="left">装修:</text>{{detail_data.renovation}}
						</view>
						<view class="li">
							<text class="left">类型:</text>{{detail_data.type}}
						</view>
						<view class="li">
							<text class="left">小区:</text>{{detail_data.community_name}}
						</view>
					</view>
				</view>
			</view>

			<view class="container">
				<view class="item">
					<view class="title">
						房源描述
					</view>
					<view class="line"></view>

					<view class="con">
						<view class="con-text">
							{{detail_data.mark}}
						</view>
					</view>
				</view>
			</view>
			<view class="container">
				<view class="item">
					<view class="title">
						房源图片
					</view>
					<view class="line"></view>

					<view class="con">
						<view class="con-text" v-for="(item,index) in detail_data.logs" :key="index">
							<image :src="item.url" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<view class="container" style="display: none;">
				<view class="item">
					<view class="title">
						房源证件
					</view>
					<view class="line"></view>

					<view class="con">
						<view class="con-text">
							<image src="/static/banner.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>

			<view class="comment">
				<view class="title">用户点评({{comment_count}})<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="con">
					<view class="empty" v-if="emptyComment">
						暂无评论
					</view>
					<view class="list" v-else>
						<view class="u-demo-block__content">
							<view class="album" v-for="(item,index) in comment_list" :key="index">
								<view class="album__avatar">
									<image :src="item.avatar" mode="" style="width: 32px;height: 32px;">
									</image>
								</view>
								<view class="album__content">
									<u--text :text="item.nickname" type="primary" bold size="17"></u--text>
									<u--text margin="0 0 8px 0" :text="item.mark"></u--text>
									<u-album :urls="item.imgs"></u-album>
								</view>
							</view>
						</view>
					</view>
					<view class="btn_submit" @click="btn_comment(detail_data.id)">
						<text>我要点评</text>
					</view>
				</view>
			</view>
			<view class="container">
				<view class="item">
					<view class="title">
						位置周边及配套
					</view>
					<view class="con">
						<view class="map">
							<map style="width: 100%; height: 200px;" :latitude="latitude" :longitude="longitude"
								:markers="covers">
							</map>
						</view>
					</view>
				</view>
			</view>
			<view class="copyright">
				<image src="/static/copyright.png" mode=""></image>
			</view>
			<view class="btn_home" @click="btn_home">返回首页</view>

			<u-tabbar :fixed="true" :placeholder="true" :value="barValue" :safeAreaInsetBottom="true">
				<u-tabbar-item text="收藏" icon="star-fill" name="sc" @click="btn_collection"></u-tabbar-item>
				<u-tabbar-item text="地图导航" icon="map"
					@click="btn_getOptionLocation(detail_data.address_lat,detail_data.address_lng,detail_data.address,detail_data.address)">
				</u-tabbar-item>
				<u-tabbar-item text="拨打电话" icon="phone" @click="btn_phone(detail_data.mobile)"></u-tabbar-item>
				<u-tabbar-item text="微信咨询" icon="chat" @click="btn_copy(detail_data.wx)"></u-tabbar-item>
			</u-tabbar>
			<u-overlay :show="showOverlay" @click="showOverlay = false">
				<view class="warp">
					<view class="rect" @tap.stop>
						<img src="/static/dialog.png" alt="" @click="btn_member">
					</view>
				</view>
			</u-overlay>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailBanner: [
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				],
				currentNum: 0,
				emptyComment: true, //评论为空
				urls2: [],
				latitude: 39.909,
				longitude: 116.39742,
				covers: [],
				showOverlay: false,
				detail_id: '',
				detail_data: [],
				error: false,
				skeleton: true,
				comment_list: [],
				comment_count: 0,
				barValue: '',
				type_index: 1
			}
		},
		methods: {
			changeBanner(e) {
				this.currentNum = e.current;
			},
			btn_member() {
				let that = this;
				uni.navigateTo({
					url: '/pages/mymember/mymember?type=2',
					success() {
						that.showOverlay = false;
					}
				})
			},
			async loadDetail() {
				let that = this;
				that.http("applet_house_detail_index", {
					id: that.detail_id
				}).then(res => {
					if (res.ec == 200) {
						console.log(res.order)
						if (res.data.order.length == 0) {
							that.error = true;
						} else {

							that.skeleton = false;
							that.detail_data = res.data.order
							that.latitude = res.data.order.address_lat;
							that.longitude = res.data.order.address_lng
							// if (res.data.order.card == 0) {
							// 	that.showOverlay = true;
							// }else{
							// 	that.showOverlay = false;
							// }
							if (res.data.order.collection == 1) {
								that.barValue = "sc";
							} else {
								that.barValue = "";
							}


						}
					} else {

					}
				})
			},
			btn_comment(id) {
				let that = this;
				uni.navigateTo({
					url: "/pages/comment/comment?id=" + id,
					success() {
						that.showOverlay = false;
					}
				})
			},
			async loadComment() {
				let that = this;
				that.http("applet_house_comment_list", {
					house_id: that.detail_id
				}).then(res => {
					if (res.ec == 200) {
						that.comment_count = res.data.count;
						if (res.data.lists.length == 0) {
							that.emptyComment = true;
						} else {
							that.emptyComment = false;
							that.comment_list = res.data.lists
						}

					}
				})
			},
			btn_phone(phone) {
				let that = this;
				that.http("applet_house_detail_index", {
					id: that.detail_id
				}).then(res => {
					if (res.ec == 200) {
						console.log(res.order)
						if (res.data.order.length == 0) {
							that.error = true;
						} else {
							// if (res.data.order.card == 0) {
							// 	that.showOverlay = true;								
							// }else{

							that.http("applet_house_detail_lesscount", {
								id: that.detail_id
							}).then(res => {
								if (res.ec == 200) {
									if (res.data.card == 0) {

										return that.showOverlay = true;
									} else if (res.data.card == 1) {
										return that.showOverlay = true;
									} else if (res.data.card == 2) {
										that.showOverlay = false;
										that.detail_data.mobile = res.data.mobile;
										that.detail_data.wx = res.data.wx
										uni.makePhoneCall({
											phoneNumber: res.data.mobile
										})
									}
								}
							})


							// }
						}
					}
				})
			},
			btn_home() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			btn_getOptionLocation(lat, lng, name, address) {
				console.log(lat, lng, name, address)
				uni.openLocation({
					latitude: parseFloat(lat),
					longitude: parseFloat(lng),
					address: address,
					name: name,
					success(res) {

					},
					fail(error) {
						console.log(error)
					}
				})
			},
			btn_copy(wx) {
				uni.setClipboardData({
					data: wx,
					success() {
						uni.$u.toast('复制成功')
					},
					fail() {
						uni.$u.toast('复制失败')
					}
				})
			},
			btn_collection() {
				let that = this;
				that.http("applet_house_collection_list", {
					house_id: this.detail_id
				}).then(res => {
					if (res.ec == 200) {
						uni.showToast({
							title: "收藏成功",
							icon: "success",
							success() {
								that.loadDetail()
							}
						})
					}
				})
			}
		},
		onLoad(option) {
			this.detail_id = option.id
			this.type_index = option.type_index
			this.loadDetail();
			this.loadComment();

		},
		onShow() {
			//this.loadDetail();
		},
		onShareAppMessage() {
			return {
				title: this.detail_data.title,
				path: '/pages/detail/detail?id=' + this.detail_id + "&type_index=" + this.type_index
			}
		},
		onShareTimeline() {
			return {
				title: this.detail_data.title,
				path: '/pages/detail/detail?id=' + this.detail_id + "&type_index=" + this.type_index
			}
		}
	}
</script>

<style lang="scss">
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}

	.rect {
		width: 523upx;
		height: 503upx;

		image {
			width: 100%;
		}
	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}

	.album {
		@include flex;
		align-items: flex-start;
		margin-top: 20rpx;

		&__avatar {
			background-color: $u-bg-color;
			padding: 5px;
			border-radius: 3px;
		}

		&__content {
			margin-left: 10px;
			flex: 1;
		}

		.u-album__row__wrapper__text {
			.u-text {
				justify-content: center;
			}
		}
	}

	.u-swiper__indicator {
		display: flex;
		width: 90%;
		text-align: right;
		justify-content: center;
		align-items: flex-end !important;
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	.head {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;

		.top {
			display: flex;
			flex-direction: row;
			width: 94%;
			margin: 0 auto;

			.top-left {
				font-size: 30rpx;
				font-weight: 600;
				white-space: nowrap;
				overflow: hidden;
				width: 600rpx;
				text-overflow: ellipsis;
			}

			.top-right {
				display: flex;
				flex-direction: row;
				font-size: 24rpx;
				color: #3084bc;
				white-space: nowrap;
				justify-content: center;
				align-items: center;

				.img {
					width: 40rpx;
					height: 40rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}
		}

		.center {
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			align-items: center;
			width: 100%;
			margin-top: 20rpx;

			.li {

				.li-top {
					color: #fe695e;
					font-size: 32rpx;
					font-weight: 600;
					width: 100%;
					overflow: hidden;
				}

				.li-bottom {
					margin-top: 10rpx;
					color: #ccc;
					font-size: 26rpx;
				}
			}
		}
	}

	.btn_home {
		position: fixed;
		top: 50%;
		background: #E91E63;
		font-size: 28rpx;
		padding: 10rpx;
		border-top-right-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
		color: #fff;
		opacity: 0.8;
	}

	.header {
		border-top: 20rpx solid #f8f8f8;
		display: flex;
		flex-direction: row;

		.item {
			width: 94%;
			margin: 0 auto;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;

			.left {
				width: 80rpx;
				height: 80rpx;
				border-radius: 100%;
				overflow: hidden;
				margin: 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.center {
				flex: 1;

				.title {
					font-weight: 400;
					margin-top: 20rpx;
				}

				.wx {
					font-size: 28rpx;
					margin: 20rpx 0;
					color: #ccc;
				}
			}

			.mobile {
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

	}

	.container {
		border-top: 20rpx solid #f8f8f8;

		.item {
			width: 94%;
			margin: 0 auto;
			font-size: 32rpx;
			padding-bottom: 20rpx;

			.title {
				margin: 20rpx 0;
			}

			.line {
				width: 100%;
				height: 1rpx;
				background-color: #f8f8f8;
				margin-bottom: 20rpx;
			}

			.con {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;

				.li {
					width: 50%;
					margin: 20rpx 0;
					font-size: 30rpx;

					.left {
						font-size: 28rpx;
						color: #888;
						margin-right: 10rpx;
					}
				}

				.con-text {
					font-size: 30rpx;
					color: #888;
				}

				.map {
					width: 100%;
				}
			}

		}
	}

	.comment {
		width: 94%;
		margin: 0 auto;
		padding-bottom: 40rpx;

		.title {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
		}

		.con {
			min-height: 200rpx;

			.empty {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 200rpx;
			}

			.list {
				.li {
					display: flex;
					flex-direction: row;
					margin-top: 20rpx;
					padding-bottom: 20rpx;
					border-bottom: 1rpx solid #f8f8f8;

					.head {
						width: 80rpx;
						height: 80rpx;
						overflow: hidden;
						border-radius: 100%;
						margin: 0 20rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.con-li {
						flex: 1;

						.title {
							color: #ccc;
							font-size: 30rpx;
							margin-bottom: 10rpx;
						}
					}
				}
			}

			.btn_submit {
				width: 90%;
				background-color: #ccc;
				color: #3084bc;
				text-align: center;
				padding: 10rpx 0;
				margin: 0 auto;
				margin-top: 20rpx;
			}
		}
	}
</style>
